﻿using OASystem.BLL.IService;
using OASystem.DAL;
using OASystem.Model;
using OASystem.ViewModel;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Text;
using System.Threading.Tasks;

namespace OASystem.BLL.Service
{
    //记得修改Userinfo成自己要使用的实体
    public class RoleService : BaseRepository<Position>, IRoleService
    {
        /// <summary>
        /// 分页
        /// </summary>
        /// <param name="page"></param>
        /// <param name="limit"></param>
        /// <param name="username"></param>
        /// <returns></returns>
        public ResponseResult RolePageList(int page, int limit, string username)
        {
            ResponseResult responseResult = new ResponseResult();
            responseResult.code = 0;
            responseResult.msg = string.Empty;
            int count = 0;
            List<Position> loginInfos = new List<Position>();
            Expression<Func<Position, bool>> whereLambda = a => true;
            if (!string.IsNullOrEmpty(username))
            {
                whereLambda = a => a.PosName.Contains(username);
            }
            Expression<Func<Position, int>> orderbyLambda = c => c.PosId;
            responseResult.data = QueryPageList(page, limit, whereLambda, orderbyLambda, out count);
            responseResult.count = count;
            return responseResult;
        }
        /// <summary>
        /// 显示编辑数据
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public ResponseResult Update(int id)
        {
            ResponseResult responseResult = new ResponseResult();

            Expression<Func<Position, bool>> whereLambda = a => a.PosId == id;
            if (Query(whereLambda) != null)
            {
                responseResult.success = true;
            }

            responseResult.data =Query(whereLambda);
            return responseResult;
        }
        /// <summary>
        /// 批量删除
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public ResponseResult MoreDel(string id)
        {
            string[] strArray = id.Split(',');
            int[] iNums;
            //string转换int[]
            iNums = Array.ConvertAll(strArray, int.Parse);
            ResponseResult result = new ResponseResult();
            result.data =BatchDeleteById(iNums);
            return result;
        }
       
    }
}
